home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / CRC.SWG / 0011_XORSUM CRC Method.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  1KB  |  55 lines

  1. {
  2. SEAN PALMER
  3.  
  4. >> (more than I thought I would have).  There were 190 collisions
  5. >> out of 572 names.
  6.  
  7. >The solution would be to use a better hashing algorythm, simply
  8. >adding up the ascii characters is not unique enough.  You best
  9. >approach would be to generate a CRC value for your hashing table
  10. >rather then the checksum approach.
  11.  
  12. Or try this xorsum method (my own invention, have to plug for it... 8)
  13.  
  14. Lots faster than a crc with no table, with similar results.
  15.  
  16. NOT compatible with a crc.
  17.  
  18. This xorsum algorithm is hereby standardized and if anyone wants to use
  19. it you should make sure your xorsum routines give the same results.
  20. }
  21.  
  22. function XorSum16(var data; size : word; prevSum : word) : word; assembler;
  23. asm
  24.   push ds
  25.   lds  si, data
  26.   mov  cx, size
  27.   mov  bx, prevSum
  28.   mov  dx, $ABCD
  29.   cld
  30.   jcxz @X
  31.  @L:
  32.   lodsb
  33.   rol  bx, 1
  34.   xor  bx, dx
  35.   xor  bl, al
  36.   loop @L
  37.  @X:
  38.   mov  ax, bx
  39.   pop  ds
  40. end;
  41.  
  42. { to use on a string, for instance: }
  43.  
  44. const
  45.   s : string = 'this is a test';
  46.  
  47. begin
  48.   writeln(xorsum16(s, length(s) + 1, 0));
  49. end.
  50. {
  51. send 0 as prevSum if you're not accumulating a result...otherwise send
  52. the result from the previous buffer.
  53. }
  54.  
  55.